<template>
    <view class="wrap savepadding">
        <!-- 加载中 -->
        <u-tabbar v-if="loading" activeColor="#1573FF" inactiveColor="#B6B6B6" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true">
            <u-tabbar-item text="loading...">
                <u-loading-icon slot="active-icon"></u-loading-icon>
                <u-loading-icon slot="inactive-icon"></u-loading-icon>
            </u-tabbar-item>
        </u-tabbar>
        <!-- 加载完成 -->
        <u-tabbar v-else activeColor="#1573FF" :key="orderConfValue" inactiveColor="#B6B6B6" :value="tab" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true">
            <template v-for="(item,index) in tabs">
                <u-tabbar-item :text="item.text" :key="index" @click="onClick(item.link)">
                    <image style="width:39upx;height:37upx" slot="active-icon" :src="item.activeIcon"></image>
                    <image style="width:39upx;height:37upx" slot="inactive-icon" :src="item.inactiveIcon"></image>
                </u-tabbar-item>
            </template>
        </u-tabbar>
    </view>
</template>

<script>
// import * as orderApi from '@/common/apis/order-api';

export default {
    props: {
        tab: {
            type: Number,
            default: 0
        }
    },
    data() {
        return {
            loading: true,
            // orderConfValue: 0,
            list: [
                {
                    text: '工作台',
                    link: '/pages/work/work',
                    activeIcon: '/static/tabBar/tabBar_workTable_selected@2x.png',
                    inactiveIcon: '/static/tabBar/tabBar_workTable_default@2x.png',
                },
                {
                    text: '车辆',
                    link: '/pages/car/car',
                    activeIcon: '/static/tabBar/tabBar_car_selected@2x.png',
                    inactiveIcon: '/static/tabBar/tabBar_car_default@2x.png',
                },
                {
                    text: '车辆监控',
                    link: '/pages/monitor/monitor',
                    activeIcon: '/static/tabBar/tabBar_monitor_selected@2x.png',
                    inactiveIcon: '/static/tabBar/tabBar_monitor_default@2x.png',
                },
                {
                    text: '订单',
                    link: '/pages/order/order',
                    activeIcon: '/static/tabBar/tabBar_order_selected@2x.png',
                    inactiveIcon: '/static/tabBar/tabBar_order_default@2x.png',
                },
            ],
        };
    },
    computed: {
        tabs() {
            if (this.loading) {
                return [];
            }
			
			/**
			 *  汽车列表开关标识  1-开通 2-未开通
				private Integer vehicleListFlag;
				订单列表开关标识  1-开通 2-未开通
				private Integer vehicleOrderFlag;
			 */
			
			let resultList=[this.list[0]]
			
			if(1==this.$store.state.params.getCarCommon.vehicleListFlag){
				resultList.push(this.list[1])
			}
			
			if(1==this.$store.state.params.getCarCommon.vehicleMonitorFlag){
				resultList.push(this.list[2])
			}
			
			if(1==this.$store.state.params.getCarCommon.vehicleOrderFlag){
				resultList.push(this.list[3])
			}
			
			
            // if (this.$store.state.params.getCarCommon.vehicleMonitorFlag !== 1) {
            //     return [
            //         this.list[0],
            //         this.list[1],
            //         // {},
            //         this.list[3],
            //     ];
            // }
            return resultList;
        },
    },
    async mounted() {
        // await this.orderConf();
        this.loading = false;
    },
    methods: {
        // async orderConf() {
        //     try {
        //         const result = await orderApi.orderConf();
        //         this.orderConfValue = result;
        //         return result;
        //     } catch (error) {
        //         uni.showToast({ title: error, icon: 'error' });
        //     }
        // },
        onClick(path) {
            // console.log(path);
            uni.switchTab({
                url: path
            });
        }
    }
};
</script>

<style lang="scss" scoped>
.wrap {
    position: relative;
    z-index: 100;
}
</style>
